package com.qc31.monitorlib.ui.popup

import android.app.Activity
import android.graphics.drawable.ColorDrawable
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import android.widget.PopupWindow
import com.qc31.baselib.utils.NaviUtil
import com.qc31.baselib.utils.isFastClick
import com.qc31.comlib.entity.GpsDetail
import com.qc31.monitorlib.databinding.PopupNaviChooseBinding

/** @Author pc_hfjs @Date 2022/2/10 10:56 @Desc */
class ChooseNaviPopup(context: Activity) : PopupWindow() {
    val binding = PopupNaviChooseBinding.inflate(LayoutInflater.from(context))
    private lateinit var endPoint: String
    private lateinit var endBLatLng: String
    private lateinit var endGLat: String
    private lateinit var endGLng: String

    init {
        contentView = binding.root

        binding.tvPopupBaidu.setOnClickListener {
            if (isFastClick()) return@setOnClickListener
            NaviUtil.startToBaiduMap(context, endPoint, endBLatLng)
            dismiss()
        }

        binding.tvPopupGaode.setOnClickListener {
            if (isFastClick()) return@setOnClickListener
            NaviUtil.startToGaodeMap(context, endPoint, endGLat, endGLng)
            dismiss()
        }

        binding.tvPopupCancel.setOnClickListener {
            dismiss()
        }

        isFocusable = true //popupwindow设置焦点
        setBackgroundDrawable(ColorDrawable(-0x56000000)) //设置背景
        //isOutsideTouchable = true //点击外面窗口消失
        width = LinearLayout.LayoutParams.MATCH_PARENT //设置SelectPicPopupWindow弹出窗体的宽
        height = LinearLayout.LayoutParams.MATCH_PARENT //设置SelectPicPopupWindow弹出窗体的高

    }

    fun showAtLocation(view: View, location: GpsDetail?) {
        location?.let {
            endPoint = it.carPlate
            endBLatLng = "${it.blat},${it.blng}"
            endGLat = it.glat
            endGLng = it.glng
        }
        super.showAtLocation(view, Gravity.NO_GRAVITY, 0, 0)
    }

}